<?php defined('RUN_KATANA') or die('Restricted access');
class ShopQuestionResponse extends Object
{
	public $OrderId;
	public $QuestionId;
	public $AnswerId;
	public $AnswerValue;
	
	public function __toString()
	{
		$out  = self::AnswerValue();
		return $out;
	}
	
	public function getOrderId() { return intval($this->OrderId); }
	public function getQuestionId() { return intval($this->QuestionId); }
	public function getAnswerId() { return intval($this->AnswerId); }
	public function getAnswerValue() { return $this->AnswerValue; }
	
	public function setOrderId($val) { $this->OrderId=intval($val); }
	public function setQuestionId($val) { $this->QuestionId=intval($val); }
	public function setAnswerId($val) { $this->AnswerId=intval($val); }
	public function setAnswerValue($val) { $this->AnswerValue=$val; }
	
	public function update()
	{
		if(self::getId() > 0)
		{
			$sql  = 'UPDATE '.DB_PERFIX.'shop_question_responses SET ';
			$sql .= '`order_id`='.self::getOrderId().', ';
			$sql .= '`question_id`='.self::getQuestionId().', ';
			$sql .= '`answer_id`='.self::getAnswerId().', ';
			$sql .= '`answer_value`="'.self::formatText(self::getAnswerValue()).'" ';
			$sql .= ' WHERE id='.self::getId().' LIMIT 1;';
			mysql_query($sql);
		}
	}
	
	public function insert()
	{
		if(self::getId() > 0)
		{ self::update(); }
		else
		{
			if((self::getOrderId() > 0) && (self::getQuestionId()) && (self::getAnswerId()))
			{
				$sql  = 'INSERT INTO '.DB_PERFIX.'shop_question_responses';
				$sql .= ' (';
				$sql .= 	'`order_id`, ';
				$sql .= 	'`question_id`, ';
				$sql .= 	'`answer_id`, ';
				$sql .= 	'`answer_value` ';
				$sql .= ' )';
				$sql .= ' VALUES ';
				$sql .= ' (';
				$sql .= ' '.self::getOrderId().', ';
				$sql .= ' '.self::getQuestionId().', ';
				$sql .= ' '.self::getAnswerId().', ';
				$sql .= '"'.self::formatText(self::getAnswerValue()).'" ';
				$sql .= ' )';
				mysql_query($sql);
			}
		}
	}
}
?>